﻿@model Bricks.Business.Models.BidManagement.BidInfo

@{
    ViewBag.Title = "招标编辑";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        initTable();  //当页面首次刷新的时候执行的事件
    });

    function initTable(queryData) {
        $('#sectionGrid').datagrid({
            url: '/BidInfo/GetSectionList?bidID=' + $("#hID").val(),
            iconCls: 'icon-bricks',
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            collapsible: true,
            pagination: false,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',
            checkOnSelect: true,
            selectOnCheck: true,
            singleSelect: true,
            queryParams: queryData,  //异步查询的参数
            toolbar: '#sectionToolBar',
            columns: [[
                { title: 'ID', field: 'ID', hidden: true },
                {
                    title: '发包标段名称', field: 'SectionName', width: 160, sortable: true,
                    editor: {
                        type: 'text',
                        options: {
                            required: true
                        }
                    }
                },
                //{ title: '招标文件', field: 'BidFile', width: 130, sortable: true, editor: 'text' },
                {
                    title: '招标文件', field: 'BidFile', width: 80, align: 'center',
                    formatter: function (value, row, index) {
                        return "<a href='javascript:void(0)' class='easyui-linkbutton' onclick='$.Upload(\"" + row.ID + "\", \"BidManagement/BidInfo/BidFile\")' data-options='plain:true,iconCls:\"icon-blue_lego\"'>附件操作</a>";
                    }
                },
                { title: '中标单位', field: 'BidUnit', width: 150, sortable: true, editor: 'text' },
                { title: '中标额', field: 'BidMoney', width: 80, sortable: true, editor: { type: 'numberbox', options: { precision: 1 } } },  //精度设置为1
                //{ title: '投标文件', field: 'EnterBidFile', width: 130, sortable: true, editor: 'text' },
                {
                    title: '投标文件', field: 'EnterBidFile', width: 80, align: 'center',
                    formatter: function (value, row, index) {
                        return "<a href='javascript:void(0)' class='easyui-linkbutton' onclick='$.Upload(\"" + row.ID + "\", \"BidManagement/BidInfo/EnterBidFile\")' data-options='plain:true,iconCls:\"icon-blue_lego\"'>附件操作</a>";
                    }
                },
                {
                    title: '操作', field: 'DeleteAction', width: 50, align: 'center',
                    formatter: function (value, row, index) {
                        //return '<a href="#" onclick="Edit.Up(this)">向上</a>&nbsp;&nbsp;<a href="#" onclick="Edit.Down(this)">向下</a>&nbsp;&nbsp;<a href="#" onclick="Edit.Delete(this)">删除</a> ';
                        return '<a href="#" onclick="Edit.Delete(this)">删除</a> ';
                    }
                },
                //{ title: 'IsDeleted', field: 'IsDeleted', hidden: true },
                //{ title: 'AddDate', field: 'AddDate', hidden: true }
            ]],
            onBeforeEdit: function (index, row) {
                row.editing = true;
                $('#sectionGrid').datagrid('refreshRow', index);
            },
            onAfterEdit: function (index, row) {
                row.editing = false;
                $('#sectionGrid').datagrid('refreshRow', index);
            },
            onCancelEdit: function (index, row) {
                row.editing = false;
                $('#sectionGrid').datagrid('refreshRow', index);
            },
            onLoadSuccess: function (data) {
                var list = data.rows;
                for (var i = 0; i < list.length; i++) {
                    EditRow(i);
                }
            }
        });
    }

    function EditRow(currentIndex) {
        $('#sectionGrid').datagrid('beginEdit', currentIndex);
    }

    var Edit = {
        //新增
        Add: function () {
            //添加新行到列表末尾
            $('#sectionGrid').datagrid('appendRow', {
                ID: $.NewGuid(),
                ActionTypeNum: 1,
                BidMoney: 0
            });
            //$.EasyuiSlide($('#sectionGrid').datagrid('getRows').length - 1);
            EditRow($('#sectionGrid').datagrid('getRows').length - 1);  //使新增行也处于编辑状态
        },

        //删除
        Delete: function (target) {

            //$.EasyuiSlide("删除选中行");  //测试
            var tr = $(target).closest('tr.datagrid-row');
            var index = parseInt(tr.attr('datagrid-row-index'));
            $('#sectionGrid').datagrid('deleteRow', index);

            //$('#sectionGrid').datagrid('acceptChanges');

            var list = $('#sectionGrid').datagrid('getData').rows;
            for (var i = 0; i < list.length; i++) {
                EditRow(i);
            }
        },

        //重置
        Reset: function () {
            $.messager.confirm('操作提示', "确认重置列表到初始状态吗？", function (r) {
                if (r) {
                    $("#sectionGrid").datagrid("reload");
                }
            })
        }
    }
</script>

<div class="frombox datagrid-body" style="padding-bottom: 5px;">
    <form id="bid-model" method="post">
        <table class="datagrid-btable" border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr class="datagrid-row">
                <td class="th">
                    <div class="datagrid-cell">项目名称</div>
                </td>
                <td class="td" colspan="5">
                    <div class="datagrid-cell">
                        <input id="projectID" name="ProjectID" data-options="required:true" value="@Model.ProjectID" />
                        @*<a href="javascript:void(0)" class="easyui-linkbutton">选择</a>*@  @*此处可考虑采用弹出框方式选择*@
                    </div>
                </td>
            </tr>
            <tr class="datagrid-row">
                <td class="th">
                    <div class="datagrid-cell">登记人</div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                        <input name="RegisterUser" class="easyui-textbox" data-options="required:false" value="@ViewBag.RegisterUser" style="background:#eeeeee;" readonly />
                    </div>
                </td>
                <td class="rth">
                    <div class="datagrid-cell">登记日期</div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                        <input name="RegisterDate" class="easyui-datebox" data-options="required:false" value="@Model.RegisterDate" />
                    </div>
                </td>
                <td class="rth">
                    <div class="datagrid-cell">招标日期</div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                        <input name="BidDate" class="easyui-datebox" data-options="required:false" value="@Model.BidDate" />
                    </div>
                </td>
            </tr>
            <tr class="datagrid-row">
                <td class="th">
                    <div class="datagrid-cell">招标形式</div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                        <input id="bidType" name="BidType" data-options="required:false" style="width:160px;" value="@Model.BidType" />
                    </div>
                </td>
                <td class="rth">
                    <div class="datagrid-cell">招标代理</div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                        <input id="bidAgent" name="BidAgent" data-options="required:false" value="@Model.BidAgent" />
                    </div>
                </td>
                <td class="rth">
                    <div class="datagrid-cell"></div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                    </div>
                </td>
            </tr>
            <tr class="datagrid-row">
                <td class="th">
                    <div class="datagrid-cell">招标联系人</div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                        <input name="BidContactPerson" data-options="required:false" value="@Model.BidContactPerson" />
                    </div>
                </td>
                <td class="rth">
                    <div class="datagrid-cell">联系电话</div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                        <input name="BidContactTel" class="easyui-textbox" data-options="required:false" value="@Model.BidContactTel" />
                    </div>
                </td>
                <td class="rth">
                    <div class="datagrid-cell"></div>
                </td>
                <td class="td">
                    <div class="datagrid-cell">
                    </div>
                </td>
            </tr>
            <tr class="datagrid-row">
                <td class="th">
                    <div class="datagrid-cell">标题</div>
                </td>
                <td class="td" colspan="5">
                    <div class="datagrid-cell">
                        <input name="BidTitle" class="easyui-textbox" data-options="required:false" style="width:670px;" value="@Model.BidTitle" />
                    </div>
                </td>
            </tr>
            <tr class="datagrid-row">
                <td class="th">
                    <div class="datagrid-cell">描述</div>
                </td>
                <td class="td" colspan="5">
                    <div class="datagrid-cell">
                        @*<input name="BidDescription" class="easyui-textbox" data-options="required:false" style="width:670px;" value="@Model.BidDescription" />*@
                        <textarea name="BidDescription" cols="93" rows="3">@Model.BidDescription</textarea>
                    </div>
                </td>
            </tr>
            <!--标段列表-->
            <tr class="datagrid-row">
                <td class="td" colspan="6">
                    <div class="datagrid-cell">
                        <div class="easyui-panel" title="标段列表">
                            <table id="sectionGrid" style="height: 210px; width: 775px;"></table>
                            <div id="sectionToolBar">
                                <a href='javascript:void(0)' class='easyui-linkbutton' onclick='Edit.Add()' data-options='plain:true,iconCls:"icon-application_add"'>新增</a>
                                <a href='javascript:void(0)' class='easyui-linkbutton' onclick='Edit.Reset()' data-options='plain:true,iconCls:"icon-reload"'>重置</a>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <input name="ID" id="hID" type="hidden" value="@Model.ID" />
        <input name="RegisterUserID" type="hidden" value="@Model.RegisterUserID" />
        <input name="IsDeleted" type="hidden" value="@Model.IsDeleted" />
        <input name="AddDate" type="hidden" value="@Model.AddDate" />
    </form>
</div>
